<template>

  <BaseAudit :callbackFn="validateForm" :submitData="childSubmitData" :isNeedDetails="isNeedDetails">
    <template v-slot:extraMiddle>
      <div>
        <span>支持人员：</span>
        <a-select show-search v-model="childSubmitData.assignVariableValue" style="width: 200px;">
          <a-select-option v-for="item in projectManagers" :key="item.id" :value="item.userId">{{item.name }}</a-select-option>
        </a-select>
      </div>
    </template>
    <template v-slot:extraAfter>
      <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
        <a-form-model ref="ruleForm" :model="form">
          <a-row :gutter="24">
            <a-col :md="8" :sm="8">
              <a-form-model-item
                :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
                label="设计需求类型 " prop="designDemandTypeId" >
                <BaseInput disabled  v-model="form.designDemandType" placeholder="请输入"  />
              </a-form-model-item>
            </a-col>
            <a-col :md="8" :sm="8">
              <a-form-model-item
                :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
                label="设计需求名称" prop="designDemandName" >
                <BaseInput disabled  v-model="form.designDemandName" placeholder="请输入"  />
              </a-form-model-item>
            </a-col>
            <a-col :md="8" :sm="8">
              <a-form-model-item
                :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
                label="期望回复时间" prop="expectRecoveryTime" >
                <BaseInput disabled  v-model="form.expectRecoveryTime" placeholder="请输入"  />
              </a-form-model-item>
            </a-col>
            <a-col :md="8" :sm="8"  >
              <a-form-model-item label="单位名称"
                                 :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                                 :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }" prop="branchId">
                <BaseInput disabled  v-model="form.branchName" placeholder="请输入"  />
              </a-form-model-item>
            </a-col>
            <a-col :md="8" :sm="8"   v-if="form.projectId">
              <a-form-model-item label="项目名称"
                                 :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                                 :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
                                 prop="projectId">
                <BaseInput disabled  v-model="form.projectName	" placeholder="请输入"  />
              </a-form-model-item>
            </a-col>
            <a-col :md="8" :sm="8"    v-if="form.projectId">
              <a-form-model-item
                :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
                label="项目编号" prop="projectNum" >
                <BaseInput v-model="form.projectNum" disabled></BaseInput>
              </a-form-model-item>
            </a-col>
            <a-col :md="8" :sm="8"  v-if="form.projectId">
              <a-form-model-item
                :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
                label="项目设计管理类别" prop="designType" >
                <BaseInput v-model="form.designType" disabled></BaseInput>
              </a-form-model-item>
            </a-col>
            <a-col :md="8" :sm="8"  >
              <a-form-model-item
                :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
                label="提出部门" prop="proposeDeptId" >
                <BaseInput v-model="form.proposeDept" disabled></BaseInput>
              </a-form-model-item>
            </a-col>
            <a-col :md="8" :sm="8"  >
              <a-form-model-item
                :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
                label="提出人" prop="proposePersonId" >
                <BaseInput v-model="form.proposePersonName" disabled></BaseInput>
              </a-form-model-item>
            </a-col>

            <!-- 公司-分公司 -->
            <a-col :md="8" :sm="8">
              <a-form-model-item  :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                                  :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
                                  label="创建人" >
                <BaseInput v-model="form.creatorName" disabled></BaseInput>
              </a-form-model-item>
            </a-col>
            <a-col :md="8" :sm="8">
              <a-form-model-item  :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                                  :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
                                  label="创建时间" >
                <BaseInput v-model="form.createTime" disabled></BaseInput>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col :md="24" :sm="24">
              <a-form-model-item :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                                 :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }" label="需求概述"   >
                <editor-bar disabled v-model="form.information" :isClear="isClear" style="width: 100%;"></editor-bar>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
        <title-name title="上传相关附件"></title-name>
        <!-- <div>
          <a-row> -->
        <!-- <a-col :md="24" :sm="19">
          <div class="table-operator"> -->
        <a-table bordered :columns="columnAssment" :data-source="dataAssement" :pagination="false">
          <span slot="serial"  slot-scope="text, record, index">{{ index + 1 }}</span>
          <span slot="action"  slot-scope="text, record, index">
                  <a :href="'/api/ycloud-file-center/oper/download?access_token='+token+'&fileId='+record.fileId" target="_parent">导出</a>
              </span>
        </a-table>
        <!-- </div> -->
        <!-- </a-col>
      </a-row>
    </div> -->
      </a-card>
    </template>
  </BaseAudit>
</template>

<script>
import Vue from 'vue'
import designDemand from '@/views/design/demand/add'
import { STable, Ellipsis } from '@/components'
import EditorBar from '@/components/Editor/editor'
import {addBasic ,getProjectType} from '@/api/design/plotsPlan'
import { getScoreList  ,addScoreList, editScoreList} from '@/api/evaluate'
import { addDemandList,getDetails ,editDemandList } from '@/api/design/demand'
import  { getTypes,getUsersDetail,getOneOrgUsers} from '@/api/commons'
import BaseAudit from '../../../views/matters/approval/components/BaseAudit'

const columns = [
  {
    title: '序号',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '计划事项',
    dataIndex: 'name'
  },
  {
    title: '计划时间',
    dataIndex: 'count',
  },
  {
    title: '责任人',
    dataIndex: 'score',
  },
  {
    title: '责任人员工编号',
    dataIndex: 'prepared',
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '150px',
    scopedSlots: { customRender: 'action' }
  }
]
const  columnApprove = [
  {
    title: '审批序号',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '审批人',
    dataIndex: '',
  },
  {
    title: '审批时间',
    dataIndex: '',
  },
  {
    title: '节点名称',
    dataIndex: '',
  },
  {
    title: '滞留时间',
    dataIndex: '',
  },
  {
    title: '审批意见',
    dataIndex: '',
  },
  {
    title: '操作',
    dataIndex: 'operation',
    scopedSlots: { customRender: 'operation' }
  }
]

const columnAssment = [
  {
    title: '序号',
    dataIndex: 'serial',
    width: '5%',
    scopedSlots: { customRender: 'serial' },
  },
  {
    title: '附件名称',
    dataIndex: 'fileName',
    width: '35%',
  },
  {
    title: '附件格式',
    dataIndex: 'suffixName',
    width: '35%',
  },
  {
    title: '操作',
    key: 'action',
    width: '20%',
    scopedSlots: { customRender: 'action' },
  },
];
export default {
  name:'a'+ Date.now(),
  components:{
    STable,
    EditorBar,
    BaseAudit,
    designDemand
  },
  data(){
    return{
      isNeedDetails:false,
      token:'',
      childSubmitData:{
        assignVariableType: 1,
        assignVariableValue: ''
      },
      title:'审批信息详情',
      columnApprove,
      titleName:'',
      dataSource:[],
      columnAssment,
      dataAssement:[],
      forms:{},
      businessId:"",
      projectManagers:[],

      // 查询参数
      queryParam: {},

      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getScoreList(requestParameters)
          .then(res => {
            return res.data
          })
      },
      selectedRowKeys:'',
      selectedRows:'',
      type:'',
      confirmLoading:false,
      columns:'',
      id:'',
      // 附件上传
      listUrl:'/cscec-project-business/inspect/query',
      deleteUrl:'/cscec-project-business/inspect/delete',
      uploadList:'/cscec-project-business/inspect/upload',
      reqMethod:'post',
      name:'',
      typeList:[],
      designType:[],
      test:'',
      isClear: false,
      information:"" ,
      editorContent: '',
      status:'',
      pageType:'',
      jobsList:[],
      userId:'',
      user:'',

      disabled:false,
      form:{} , // 需求申请数据
      visible:false,

    }
  },
  computed: {
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
        selectedRows: this.selectedRows,   // 当前行所有数据
        onChange: this.onSelectChange
      }
    }
  },
  created() {
    this.userId = JSON.parse(sessionStorage.getItem('ycloud-user_info')).id
    this.user = JSON.parse(sessionStorage.getItem('ycloud-user_info')).username
    this.token = Vue.getAcloudProvider().getAccessToken()
    this.id = this.$route.query.id
    this.businessId = this.$route.query.id
    this.status = this.$route.query.status
    this.type = this.$route.query.type
    if(this.type=='add'){
      this.titleName="新增设计需求申请"
    }else if(this.type=='edit'){
      this.titleName="编辑设计需求申请"
    }
    this.getTypes()
    this.getDetails()
    this.getUsersDetail()
    this.getProjectManager()
    // this.getjobsList()
    // this.getScoreList()
  },
  // mounted(){
  //     var editor = new E('#editorElem')
  //     editor.customConfig.onchange = (html) => {
  //       this.editorContent = html
  //     }
  //     editor.create()
  // },
  methods:{
    validateForm(value){
      if(value == 'unApproval'){
        return true
      }
      if(this.childSubmitData.assignVariableValue == ""){
        this.$message.error("请选择支持人员!")
        return false;
      }
      return true;
    },
    handelUnApproval(){  // 审批不通过
      this.$confirm({
        title: '警告提醒！',
        content: '确定审批不通过？',
        okType: 'danger',
        onOk() {

        },
        onCancel() {

        },
      });
    },

    handelApproval(){    // 审批通过  判断(支持人员必填)
      this.$confirm({
        title: '警告提醒！',
        content: '确定审批通过？',
        okType: 'danger',
        onOk() {

        },
        onCancel() {
        },
      });
    },

    getProjectManager() {
      getOneOrgUsers({orgCodes:['designManage'],pageSize:1000,pageNumber:1}).then(res => {
        this.projectManagers = res.data.list
      })
    },
    getDetails(){
      if(this.id){
        getDetails({id:this.id}).then(res=>{
          this.form = res.data
          console.log(res.data)
          this.dataAssement = res.data.designFileIdsInfo
          if(!this.dataAssement){
            this.dataAssement=[]
          }
        })
      }
    },
    // getDetails(){
    //   if(this.id){
    //     getDetails({id:this.id}).then(res=>{
    //       this.form = res.data
    //     })
    //   }
    // },
    getUsersDetail(){
      getUsersDetail({userId:this.userId}).then(res=>{})
    },
    selectProject(value){
      console.log(value)
      let arr=[]
      arr.push(value)
      getProjectType({projectIds:arr}).then(res=>{
        console.log(res.data)
        this.form.projectNum = res.data[0].projectNumber
        this.form.designType = res.data[0].designTypeName
        this.form.designTypeId = res.data[0].designTypeId
        // if(this.form.designType=="B类"){
        //   this.tableData = this.tableData1
        // }else if(this.form.designType=="C类"){
        //   this.tableData = this.tableData2
        // }
      })
    },
    getTypes(){
      getTypes({type:'22'}).then(res=>{
        this.typeList = res.data
      })
    },
    // getjobsList(){
    //   getjobsList().then((res)=>{
    //     this.jobsList = res.data
    //   })
    // },
    getScoreList(){
      getScoreList().then(res=>{
        this.loadData = res.data
      })
    },
    save(){
      this.$refs.ruleForm.validate(valid=>{
        if(valid){
          this.form.statusCode='0'
          if(this.id){
            editDemandList(this.form).then(res=>{
              this.$router.push("/project/design/demand")
              if(res.code='200'){
                this.$message.success("保存草稿成功")
              }
            })
          }else{
            addDemandList(this.form).then(res=>{
              this.$router.push("/project/design/demand")
              if(res.code='200'){
                this.$message.success("保存草稿成功")
              }
            })
          }
        }else {
          //this.$message.warning("请填写完所有必填项信息")
        }
      })
    },
    saveSubmit(){
      this.$refs.ruleForm.validate(valid=>{
        if(valid){
          this.form.statusCode='1'
          if(this.id){
            editDemandList(this.form).then(res=>{
              this.$router.push("/project/design/demand")
              if(res.code='200'){
                this.$message.success("提交成功")
              }
            })
          }else{
            addDemandList(this.form).then(res=>{
              this.$router.push("/project/design/demand")
              if(res.code='200'){
                this.$message.success("提交成功")
              }
            })
          }
        }else {
          this.$message.warning("请填写完所有必填项信息")
        }
      })
    },

    change(value){
      console.log(value)
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      console.log(selectedRowKeys)
      console.log(selectedRows)
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    search(){
      this.$refs.table.refresh(true)
    },
    goAdd(){
      this.visible = true
    },
    handleSub(record,type){
      this.visible = true
      this.type = type
      this.form = record
    },
    handleEdit(record){
      this.visible = true
      this.form = record
    },
    handleOk(){
      this.visible = false
      if(this.form.id){
        editScoreList(this.form).then((res)=>{
          if(res.code=='200'){
            this.$message.success("编辑成功")
          }
        })
      }else{
        addScoreList(this.form).then((res)=>{
          if(res.code=='200'){
            this.$message.success("新增成功")
          }
          this.$refs.table.refresh(true)
        })
      }
    },
    handleCancel(){
      this.visible = false
    }
  }
}
</script>


